 <?php
 require_once(dirname(__FILE__).'/exception.php');
   require_once(dirname(__FILE__).'/property.php');
function getToken($regetOuttimeTokenMeth,$tokenCacheFile,$timeoutHours)
{
	if(!file_exists( $tokenCacheFile))
	{
		file_put_contents($tokenCacheFile, ''); 
	
	}
	$prp=readini($tokenCacheFile);
	if($prp)
	{
		$GLOBALS["varsx"]["token_frm_file"]=$prp["token"];
	 
		$timex=$prp["timex"];
		if(timeoutx($timex,$timeoutHours))
		{
		}
		else if($prp["token"]!="")
		{
			//echo "111";
			$GLOBALS["stack"][]="tokenis not empty";
			return $prp["token"];
		}
	}
	$GLOBALS["stack"][]="wile new token";
	//echo "wile new token";
	$new_token=	$regetOuttimeTokenMeth();
	$a["timex"]=date("Y-m-d H:i:s");//time();
	$a["token"]=$new_token;
	print_r($a);
	write_ini_file($a,$tokenCacheFile);
	return $new_token;
	
	
	/*$time1,$time2假设这两个是你的时间
$time1 = strtotime($time1);
$time2 = strtotime($time2);
$time = $time2-$time1;*/
}
 
 function timeoutx($time_str,$timeOutHours)
 {
	$time=strtotime ($time_str);
	 $span=time()-$time;
	 if($span>$timeOutHours*3600)
		 return true;
	 else
		 return false;
	 
 }
 
 
 function main()
 {
	 echo getToken(function(){return "tonen_xxxxx_4 test";},"c:/token.txt",2);
	 
 }
// main();
 ?>